﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;

namespace LTorrent.Peers
{
    class HandshakeMessage: IPeerMessages
    {
        readonly Byte[] pstr = Encoding.ASCII.GetBytes("BitTorrent protocol");
        readonly Byte[] reserved = { 0, 0, 0, 0, 0, 0, 0, 0 };

        protected MemoryStream _Message;

        public static Int32 Length = 68;

        public HandshakeMessage(Byte[] Info_hash, Byte[] Peer_id)
        {
                _Message = new MemoryStream();
                _Message.WriteByte((Byte)pstr.Length);
                _Message.Write(pstr, 0, pstr.Length);
                _Message.Write(reserved, 0, reserved.Length);
                _Message.Write(Info_hash, 0, Info_hash.Length);
                _Message.Write(Peer_id, 0, Peer_id.Length);
        }
        ~HandshakeMessage()
        {
            _Message.Close();
        }



        public Byte[] Message
        {
            get { return _Message.ToArray(); }
        }
    }
}
